package com.taiyi.crm.controller;

import com.taiyi.crm.pojo.entity.Permission;
import com.taiyi.crm.pojo.vo.LayUISelectMVO;
import com.taiyi.crm.service.IPermissionService;
import com.taiyi.crm.util.JSONResult;
import com.taiyi.crm.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RequestMapping("/permission")
@Controller
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @ApiIgnore
    @RequestMapping("/getPermissionPage")
    public String getPermissionPage() {
        return "/permission/permission_list";
    }


    @RequestMapping("/list")
    @ResponseBody
    public LayUITableResult list(Integer page, Integer limit, Permission permission) {
        return permissionService.list(page, limit, permission);
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer id) {
        permissionService.deleteById(id);
        return JSONResult.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    @ResponseBody
    public JSONResult deleteAll(String ids) {
        permissionService.deleteAll(ids);
        return JSONResult.ok("删除成功");
    }

    @RequestMapping("/getInsertPage")
    public String getInsertPage() {

        return "/permission/permission_insert";
    }
    @RequestMapping("/getPermissionUpdatePage")
    public String getPermissionUpdatePage() {
        System.out.println("PermissionController.getPermissionUpdatePage");
        return "/permission/permission_update";
    }

    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Permission permission) {
        permissionService.insert(permission);
        return JSONResult.ok("添加成功");
    }


    @RequestMapping("/selectAllPermisssions")
    @ResponseBody
    public JSONResult selectAllPermisssions() {
        List<LayUISelectMVO> list = permissionService.selectAllPermisssions();
        return JSONResult.ok(list);
    }
}